from django.shortcuts import render,HttpResponseRedirect,HttpResponse
from django.shortcuts import redirect
from users.models import User
from users.service.menuControl import intial_session
# Create your views here.
def login(request):
    if request.method == 'POST':
        username = request.POST.get("username")
        password = request.POST.get("password")
        user = User.objects.filter(name=username, pwd=password).first()
        if user:
            request.session["user_id"] = username
            # request.session['is_login'] = True
            intial_session(user, request)
            return redirect("/monitor/recordtable/")
   #         response = HttpResponseRedirect('/monitor/recordtable')
    return render(request, 'users/login.html')

def logout(request):
    request.session.clear() #清除所有的session记录，就可以直接注销了
    return HttpResponseRedirect("/users/login")